import type { PreOrder } from '@/types/cartItem'
import type {
  OrderCreateParams,
  OrderListParams,
  OrderListResult,
  OrderResult,
} from '@/types/order'
import { http } from '@/utils/http'

//提交订单
export const postMemberOrderAPI = (order: OrderCreateParams) => {
  return http<{ id: number }>({
    method: 'POST',
    url: '/member/order/addOrder',
    data: order,
  })
}

//获取订单详情
export const getMemeberOrderByIdAPI = (id: number) => {
  return http<OrderResult>({
    method: 'GET',
    url: '/member/order/findById',
    data: { id },
  })
}

//获取订单列表
export const getMemberOrderAPI = (orderParam: OrderListParams) => {
  return http<OrderListResult>({
    method: 'POST',
    url: '/member/order/pageOrderList',
    data: orderParam,
  })
}

//立即购买
export const buyAgainAPI = (userId: number, orderId: number) => {
  return http<PreOrder>({
    method: 'POST',
    url: '/member/order/buyAgain',
    data: { userId, orderId },
  })
}

//收货
export const takeGoodsAPI = (id: number) => {
  return http({
    method: 'GET',
    url: '/member/order/takeGoods',
    data: { id },
  })
}

//评价
export const reviewAPI = (id: number) => {
  return http({
    method: 'GET',
    url: '/member/order/review',
    data: { id },
  })
}
